\usepackage{color}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{caption}
\usepackage{geometry}
\usepackage{float}

%\renewcommand*\familydefault{\ttdefault}
\newcommand{\pref}[1]{[\ref{#1}, page \pageref{#1}]}

\definecolor{cgreen}{rgb}{0.0,0.6,0.0}
\definecolor{brown}{rgb}{0.7,0.6,0.1}

\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in }
\lstset{ %
  frame=top,frame=bottom,
  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  captionpos=t,                    % sets the caption-position to bottom
  commentstyle=\color{cgreen},    % comment style
  deletekeywords={...},            % if you want to delete keywords from the given language
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{red},       % keyword style
  language=Lisp,                 % the language of the code
  morekeywords={*,defsimulation,defenvironment,defagent,defpercept,defactuator,defgsimulation,...},            % if you want to add more keywords to the set
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt,                   % how far the line-numbers are from the code
  numberstyle=\tiny\color{cgreen}, % the style that is used for the line-numbers
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
  stringstyle=\color{brown},     % string literal style
  tabsize=2,                       % sets default tabsize to 2 spaces
}

\DeclareCaptionFormat{listing}{\rule{\dimexpr\textwidth+17pt\relax}{0.4pt}\par\vskip1pt#1#2#3}
\captionsetup[lstlisting]{format=listing,singlelinecheck=false, margin=0pt, font={sf},labelsep=space,labelfont=bf}

\renewcommand\lstlistingname{Example}

\lstnewenvironment{example}[1][]{
\lstset{#1}
}{
}

\lstnewenvironment{snippet}{
\lstset{}
}{
}